import { useDispatch, useSelector } from "react-redux";
import { setName as setSchoolName } from "./RTK-store/schoolSlice";
import { setAge, setName } from "./RTK-store/stuSlice";
function App() {
  // useSelector用来加载state数据
  const student = useSelector(state => state.student);
  const school = useSelector(state => state.school);
  // useDispatch获取派发器
  const dispatch = useDispatch();
  // 获取action的构建器
  const setNameHandler = () => {
    dispatch(setName('王五'))
  }
  const setAgeHandler = () => {
    dispatch(setAge(21))
  }
  const setSchoolNameHandler = () => {
    dispatch(setSchoolName('中学'))
  }
  return (
    <div className="App">
      <p>
        {student.name} --
        {student.age} --
        {student.gender}
      </p>
      <p>
        {school.name}--
        {school.address}
      </p>
      <button onClick={setNameHandler}>修改name</button>
      <button onClick={setAgeHandler}>修改age</button>
      <button onClick={setSchoolNameHandler}>修改学校name</button>
    </div>
  );
}

export default App;
